home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: messageStats.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:12 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include <stdio.h>
- #include <errno.h>
- #include "ess.h"
- #include "msgstats.h"
- #include "lsn.h"
- #include "io.h"
- #include "msgdefs.h"
-
- MESSAGESTATS MsgStats;
- extern MESSAGENAME MsgNames[];
-
- MESSAGENAME MsgNames[] = {
- { NULL, /* unused */ 0},
- { "MountVolume", 1},
- { "DismountVolume", 2},
- { "FormatVolume", 3},
- { "ReadPage", 4},
- { "WritePage", 5},
- { "AllocPages", 6},
- { "DeallocPages", 7},
- { "CheckBitmap", 8},
- { "GetUnique", 9},
- { "StatVolume", 10},
- { "SetRootEntry", 11},
- { "GetRootEntry", 12},
- { NULL, /*unused*/ 13},
- { "ExternalBegin", 14},
- { "ExternalCommit", 15},
- { "ExternalAbort", 16},
- { "LockPage", 17},
- { "LockFile", 18},
- { "CreateFile", 19},
- { "DestroyFile", 20},
- { "FirstPhysicalPage", 21},
- { "LastPhysicalPage", 22},
- { "NeighborPage", 23},
- { "FirstLogicalPage", 24},
- { "LastLogicalPage", 25},
- { "MarkPage", 26},
- { "ResetRusage", 27},
- { "GetRusage", 28},
- { "CreateSequentialFile", 29},
- { "OpenSequentialLoad", 30},
- { "OpenSequentialScan", 31},
- { "ScanNextSequential", 32},
- { "LoadNextSequential", 33},
- { "CloseResource", 34},
- { "TestNullRpc", 35},
- { "TestPageRpc", 36},
- { "WriteLogPage", 37},
- { "InitClient", 38},
- { "UnlockPage", 39},
- { "UnlockFile", 40},
- { "QueryPage", 41},
- { "SetAnchor", 42},
- { "SetCLR", 43},
- { "MonDump", 44},
- { "TakeCheckpoint", 45},
- { "ChangeCheckpointFreq", 46},
- { "ShutServer", 47},
- { "Statistics", 48},
- { "DebugSetVar", 49},
- { "TestPageSend", 50},
- { "SyncTransaction", 51},
- { "FileNumPages", 52},
- { "Enter2PC", 53},
- { "ClientPrepare", 54},
- { "CoordPrepare", 55},
- { "Vote", 56},
- { "ClientDecision", 57},
- { "Continue2PC", 58},
- { "Recover2PC", 59},
- { "CoordDecision", 60},
- { "ServerAck", 61},
- { "AddVolume", 62},
- { "RemoveVolume", 63}
-
- };
-
- static int msglen = 19;
- static int mnumlen = 3;
- static int sumlen = 9;
- static char *labelslashformat = "%*.*s/%-*.*s: %*.*s %*.*s %*.*s %*.*s %*.*s\n";
- static char *labelformat = "%*.*s %-*.*s: %*.*s %*.*s %*.*s %*.*s %*.*s\n";
- static char *numformat = "%*.*s/%-*d: %*d %*d %*d %*d %*d\n";
- static char *total1format = "%*.*s : %*d %*d %*d %*d %*d\n";
- static char *sentrcvformat = "%*.*s : %*d %*d \n";
- static char *underscores = "___________________________________________________";
-
- void
- printMessageStats(
- FILE *const f,
- MESSAGESTATS *const msgStats
- )
- {
- register int i,
- sent=0, received=0, replied_ok=0,
- replied_in_error=0, no_reply_requested=0;
- BOOL first = TRUE;
-
- #define ANY(j)\
- ((msgStats->received[j] + MsgStats.sent[j] +\
- msgStats->no_reply_requested[j] +\
- msgStats->replied_in_error[j] + MsgStats.replied_ok[j]) > 0)
-
- for( i=0; i <= MAX_MSG_NUMBER; i++) {
- if( ANY(i) ) {
- if(first) {
- fprintf(f,"MESSAGE ACTIVITY:\n");
- fprintf(f, labelslashformat,
- msglen, msglen, "MESSAGE",
- mnumlen, mnumlen, "#",
- sumlen, sumlen, "SENT",
- sumlen, sumlen, "RECEIVED",
- sumlen, sumlen, "",
- sumlen, sumlen, "REPLIES",
- sumlen, sumlen, "");
-
- fprintf(f, labelformat,
- msglen, msglen, "",
- mnumlen, mnumlen, "",
- sumlen, sumlen, "",
- sumlen, sumlen, "",
- sumlen, sumlen, "no reply",
- sumlen, sumlen, "in error",
- sumlen, sumlen, "OK");
-
- fprintf(f, labelformat,
- msglen, msglen, underscores,
- mnumlen,mnumlen,underscores,
- sumlen, sumlen, underscores,
- sumlen, sumlen, underscores,
- sumlen, sumlen, underscores,
- sumlen, sumlen, underscores,
- sumlen, sumlen, underscores);
- first = FALSE;
- }
-
- fprintf(f, numformat,
- msglen, msglen, MsgNames[i].name,
- mnumlen, i,
- sumlen, msgStats->sent[i],
- sumlen, msgStats->received[i],
- sumlen, msgStats->no_reply_requested[i],
- sumlen, msgStats->replied_in_error[i],
- sumlen, msgStats->replied_ok[i]);
-
- sent += msgStats->sent[i];
- received += msgStats->received[i];
- no_reply_requested += msgStats->no_reply_requested[i];
- replied_in_error += msgStats->replied_in_error[i];
- replied_ok += msgStats->replied_ok[i];
- }
- }
- if(first) {
- fprintf(f,"NO MESSAGE ACTIVITY.\n");
- } else {
-
- fprintf(f, labelformat,
- msglen, msglen, underscores,
- mnumlen,mnumlen,underscores,
- sumlen, sumlen, underscores,
- sumlen, sumlen, underscores,
- sumlen, sumlen, underscores,
- sumlen, sumlen, underscores,
- sumlen, sumlen, underscores);
- fprintf(f, total1format,
- msglen+mnumlen, msglen+mnumlen, "Total",
- sumlen, sent,
- sumlen, received,
- sumlen, no_reply_requested,
- sumlen, replied_in_error,
- sumlen, replied_ok);
- fprintf(f, sentrcvformat,
- msglen+mnumlen, msglen+mnumlen, "Total bytes",
- sumlen, msgStats->bytes_sent,
- sumlen, msgStats->bytes_received);
- fprintf(f, sentrcvformat,
- msglen+mnumlen, msglen+mnumlen, "Full page equiv",
- sumlen, msgStats->pages_sent,
- sumlen, msgStats->pages_received);
- fprintf(f, sentrcvformat,
- msglen+mnumlen, msglen+mnumlen, "Partial page equiv",
- sumlen, msgStats->partial_pages_sent,
- sumlen, msgStats->partial_pages_received);
- }
- }
-
- void
- incPages(int totalBytes, int direction, BOOL includesMessage)
- {
- int *sum, *partial;
- int extra, pages;
-
- switch(direction) {
- case SENT:
- MsgStats.bytes_sent += totalBytes;
- sum = &MsgStats.pages_sent;
- partial = &MsgStats.partial_pages_sent;
- break;
-
- case RECEIVED:
- MsgStats.bytes_received += totalBytes;
- sum = &MsgStats.pages_received;
- partial = &MsgStats.partial_pages_received;
- break;
-
- default:
- /* SM_ERROR(TYPE_FATAL, esmINTERNAL); */
- break;
- }
-
- if(includesMessage) {
- extra = totalBytes - sizeof(MESSAGE);
- } else {
- extra = totalBytes;
- }
-
-
- (*sum) += (pages = (extra / MIN_PAGESIZE));
- if( (pages * MIN_PAGESIZE) < extra ) {
- (*partial) ++;
- }
- }
-